package com.multiplayer.control;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.multiplayer.service.IUserService;
import com.multiplayer.service.impl.UserServiceImpl;
import com.multiplayer.tools.PageData;

/**
 * Servlet implementation class UserManagerServlet
 */
@WebServlet("/UserManagerServlet")
public class UserManagerServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	//用户服务层依赖
    IUserService userService = new UserServiceImpl();
    
    public UserManagerServlet() {
        super();
      
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String op = request.getParameter("op");

		System.out.println("得到的admin"+request.getSession().getAttribute("admin"));
		System.out.println("得到的user"+request.getSession().getAttribute("user"));
		if("searchAll".equals(op)) {
			//查询所有成员
		  int page = Integer.parseInt(request.getParameter("page"));
		  int pageSize = Integer.parseInt(request.getParameter("pageSize"));
		  
		  PageData pageData = userService.searchAllUserByPage(page, pageSize);
		  System.out.println(pageData.getData());
		  request.setAttribute("pageData", pageData);

		if("searchAll".equals(op)) {
			//查询所有成员
		  int page1 = Integer.parseInt(request.getParameter("page"));
		  int pageSize1 = Integer.parseInt(request.getParameter("pageSize"));
		  
		  PageData pageData1 = userService.searchAllUserByPage(page1, pageSize1);
		  System.out.println(pageData1.getData());
		  request.setAttribute("pageData", pageData1);
		  System.out.println("diaozhege");

		  request.getRequestDispatcher("UserManager.jsp").forward(request, response);
		  
		}else if("searchBySno".equals(op)) {
			//按学号查询一个成员
		}else if("serchLike".equals(op)) {
			//按学院模糊查询
		}
		}
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}
